/***********************************************************************
 * Module:  Annee.java
 * Author:  Alexandro
 * Purpose: Defines the Class Annee
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;
import java.util.Vector; 

public class Annee implements InterfaceDAO {
   private int noAnnee;
   private int codeDip;
   
   public Etudiant[] etudiant;
   public Module[] module;
   
   public int getNoAnnee() {
      return noAnnee;
   }
   
   /** @param newNoAnnee */
   public void setNoAnnee(int newNoAnnee) {
      noAnnee = newNoAnnee;
   }
   
   public int getCodeDiplome() {
      return codeDip;
   }
   
   /** @param newCodeDip */
   public void setCodeDiplome(int newCodeDip) {
      codeDip = newCodeDip;
   }
   
   
   public int insert(int[] fk) {
      try {			
			dao.DAODataConnection.executer("INSERT INTO annee VALUES("+getCodeDiplome()+","+getNoAnnee()+");");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
   }
   
   public Object[] select(int[] param) {
      
        
      try {			
			
			ResultSet table = dao.DAODataConnection.executerQuery("SELECT * FROM annee");											
			Vector sortie = new Vector();			
			while(table.next() )	
			{
				Annee neuf = new Annee();
				neuf.setCodeDiplome(table.getInt(1));
				neuf.setNoAnnee(table.getInt(2));
				sortie.add(neuf);				
			}		
			return sortie.toArray();			
			}
			
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
   }
   
   public int delete(int[] param) {
      try {			
			dao.DAODataConnection.executer("DELETE FROM annee WHERE code_dip="+getCodeDiplome()+" and no_annee="+getNoAnnee());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
   }
   
   public int update(int[] params) {
     
		return 1;
		
   }

}